<template>
  <div class="diet-manage">
    <!-- 顶部Banner图片 -->
    <div class="banner">
      <img src="https://images.unsplash.com/photo-1504674900247-0877df9cc836?auto=format&fit=crop&w=800&q=80"
        alt="健康饮食" />
    </div>

    <h2>
      <el-icon style="vertical-align: middle; color: #67c23a;">
        <Bowl />
      </el-icon>
      个性化膳食推荐
    </h2>
    <div class="recommendation">
      <el-carousel height="60px" indicator-position="outside">
        <el-carousel-item v-for="(item, idx) in recommendations" :key="idx">
          <div class="recommend-item">
            <img :src="item.img" class="recommend-img" alt="推荐" @error="e => e.target.src = defaultImg" />
            <span>{{ item.text }}</span>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>

    <h2 style="margin-top: 30px;">
      <el-icon style="vertical-align: middle; color: #409EFF;">
        <EditPen />
      </el-icon>
      每日膳食反馈
    </h2>
    <el-card class="feedback-card">
      <el-form @submit.prevent="submitFeedback" class="feedback-form">
        <el-form-item label="今日饮食反馈">
          <el-input v-model="feedback" type="textarea" placeholder="请输入您的饮食反馈，并描述饮食后皮肤的变化（如有无新痘、泛红、干燥等）" />
        </el-form-item>
        <div class="feedback-btn-row">
          <el-button type="primary" @click="submitFeedback">提交反馈</el-button>
        </div>
      </el-form>
    </el-card>

    <div v-if="feedbackList.length" class="history-section">
      <h3>
        <el-icon style="vertical-align: middle; color: #e6a23c;">
          <Memo />
        </el-icon>
        历史反馈
      </h3>
      <el-timeline>
        <el-timeline-item v-for="(item, idx) in feedbackList" :key="idx" :timestamp="item.date" placement="top">
          <el-card>
            <div class="history-content">
              <img :src="item.img || defaultImg" class="history-img" alt="反馈" @error="e => e.target.src = defaultImg" />
              <span>{{ item.text }}</span>
            </div>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </div>
  </div>
</template>

<script setup>
import { Bowl, EditPen, Memo } from '@element-plus/icons-vue'
import { ref } from 'vue'

const defaultImg = 'https://img.icons8.com/ios-filled/50/vegetarian-food.png'

const feedback = ref('')
const feedbackList = ref([
  {
    text: '早餐：燕麦牛奶+蓝莓，午餐：三文鱼+西兰花，晚餐：鸡胸肉+蔬菜沙拉。皮肤状态：无新痘，肤色较好。',
    date: '2024-05-01',
    img: 'https://images.unsplash.com/photo-1464306076886-debca5e8a6b0?auto=format&fit=crop&w=400&q=80'
  },
  {
    text: '早餐：全麦面包+牛油果，午餐：番茄牛腩，晚餐：水果沙拉。皮肤状态：有轻微出油，无明显不适。',
    date: '2024-04-30',
    img: 'https://images.unsplash.com/photo-1519864600265-abb23847ef2c?auto=format&fit=crop&w=400&q=80'
  }
])

const recommendations = [
  {
    text: '多吃富含维生素A、C、E的食物，如胡萝卜、蓝莓、坚果，有助于皮肤修复和抗氧化。',
    img: 'https://images.unsplash.com/photo-1502741338009-cac2772e18bc?auto=format&fit=crop&w=80&q=80'
  },
  {
    text: '避免高糖高脂饮食，减少油炸食品摄入，有助于预防痤疮和皮肤炎症。',
    img: 'https://images.unsplash.com/photo-1519864600265-abb23847ef2c?auto=format&fit=crop&w=80&q=80'
  },
  {
    text: '多喝水，适量补充优质蛋白，有助于皮肤屏障修复。',
    img: 'https://images.unsplash.com/photo-1465101046530-73398c7f28ca?auto=format&fit=crop&w=80&q=80'
  }
]

function submitFeedback() {
  if (feedback.value.trim()) {
    feedbackList.value.unshift({
      text: feedback.value + ' 皮肤状态：请描述饮食后皮肤的变化，如有无新痘、泛红、干燥等。',
      date: new Date().toLocaleDateString(),
      img: 'https://images.unsplash.com/photo-1464306076886-debca5e8a6b0?auto=format&fit=crop&w=400&q=80'
    })
    feedback.value = ''
  }
}
</script>

<style scoped>
.diet-manage {
  padding: 20px;
  max-width: 600px;
  margin: 0 auto;
}

.banner img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 18px;
}

.recommendation {
  background: #e8f5e9;
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.recommend-item {
  display: flex;
  align-items: center;
}

.recommend-img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  margin-right: 12px;
  object-fit: cover;
  background: #f6f6f6;
}

.feedback-card {
  background: #f8fafd;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  margin-bottom: 30px;
  padding-bottom: 10px;
}

.feedback-form {
  margin-bottom: 0;
}

.feedback-btn-row {
  display: flex;
  justify-content: flex-end;
}

.history-section {
  margin-top: 30px;
}

.history-content {
  display: flex;
  align-items: center;
}

.history-img {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  margin-right: 10px;
  object-fit: cover;
  background: #f6f6f6;
}
</style>